﻿using System;
using ParserGenerator.GrammarConstruction;

namespace ParserGenerator.ParserConstruction
{
    [Serializable]
    public sealed class ParserAutomatonTransition
    {
        public ParserAutomatonState State { get; }
        public GrammarSymbol Symbol { get; }
        public ParserAutomatonState Target { get; }

        public bool IsShift => Symbol.IsTerminal;
        public bool IsGoto => Symbol.IsNonterminal;

        internal ParserAutomatonTransition(ParserAutomatonState state, GrammarSymbol symbol, ParserAutomatonState target)
        {
            if (state == null)
                throw new ArgumentNullException(nameof(state));
            if (target == null)
                throw new ArgumentNullException(nameof(target));
            if (symbol == null)
                throw new ArgumentNullException(nameof(symbol));
            State = state;
            Symbol = symbol;
            Target = target;
        }

        public sealed override string ToString()
        {
            if (IsShift)
                return "shift to " + Target.Number;
            else
                return "goto " + Target.Number;
        }
    }
}
